from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout
from django.template import RequestContext
from django.http import HttpResponseRedirect
from optitrans.domain.vehicule import Vehicule
from django.core import serializers
from django.utils import simplejson
from optitrans.domain.arret import Arret
from optitrans.form.chauffeur import ChauffeurForm

@login_required
def home(request):
    vehicules = Vehicule.objects.all();
    geodata =  serializers.serialize('json', vehicules);
    return render_to_response('pages/home.html', {'vehicules':vehicules,'geodata':geodata}, context_instance=RequestContext(request))
   


@login_required
def moncompte(request):
    return render_to_response('pages/compte.html')

@login_required
def config(request):
    chauffeur=ChauffeurForm()
    return render_to_response('pages/configuration.html',{"chauffeur":chauffeur},context_instance=RequestContext(request))


@login_required
def rapport(request):
    return render_to_response('pages/rapport.html')


@login_required
def gestion(request):
    return render_to_response('pages/gestion.html')


def ficheVehicule(request):
    return render_to_response('pages/ficheVehicule.html')

def logout_page(request):
    logout(request)
    request.session.flush()
    return HttpResponseRedirect('/optitrans') 
   


